#!/usr/bin/env python
# -*- coding: utf-8 -*-

import rospy
from sensor_msgs.msg import LaserScan
from std_msgs.msg import String
from geometry_msgs.msg import Twist

def callback(data):
	for x in range(th_a, th_b):
		if data.ranges[x] < dis:
			flag = 0
			break
	if (flag):
		pub.publish(vel)
		rospy.loginfo("rush! %d" %(vel.linear))

	
if __name__ == '__main__':
	
	# values
	vel = Twist()
	dis = 2
	rangee = 60
	th_a = -rangee/2
	th_b = rangee/2
	flag = 1
	vel.linear.x = 1590

	# init ROS
	rospy.init_node('LastRush', anonymous=False)
	pub = rospy.Publisher("/car/cmd_vel", Twist, queue_size=10)
	rospy.Subscriber("scan", LaserScan, callback)
	rospy.spin()

